<template>
  <div
    class="sub-page-header"
    ref="subPageHeader"
  >
    <div class="sub-page-header-left">
      <div
        class="back-box"
        @click="backFn"
      >
        <i class="el-icon-back"></i>
        返回
      </div>
      <div
        class="sub-page-title"
        v-if="options.title"
      >{{ options.title }}</div>
    </div>
    <div
      class="sub-page-header-right"
      v-if="options.buttons"
    >
      <el-button
        v-for="button in options.buttons"
        :key="button.label"
        :type="button.type"
        @click="button.handleClick()"
      >{{ button.label }}</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SubPageHeader',
  props: {
    subPageHeaderOptions: {
      type: Object,
      default: () => {
        return {};
      },
      require: true
    }
  },
  computed: {
    // 参数
    options() {
      return this.subPageHeaderOptions;
    }
  },
  methods: {
    // 返回
    backFn() {
      this.$router.back();
    }
  }
};
</script>

<style lang="scss" scoped>
.sub-page-header {
  flex-shrink: 0;
  width: 100%;
  height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid #ebeef5;

  .sub-page-header-left {
    display: flex;
    align-items: center;
    line-height: normal;

    .back-box {
      padding-right: 15px;

      &:hover {
        cursor: pointer;
        color: var(--color-primary);
      }
    }

    .sub-page-title {
      position: relative;
      padding-left: 15px;
      font-size: 18px;

      &::before {
        content: '';
        position: absolute;
        top: 4px;
        left: 0;
        width: 1px;
        height: 16px;
        background-color: #c0c4cc;
      }
    }
  }
}
</style>
